import java.util.Set;
import java.util.TreeSet;

public class StringLengthSort {
    public static void main(String[] args) {
        Set<String> set = new TreeSet<>((s1, s2) -> {
            if (s1.length() == s2.length()) {
                return s1.compareTo(s2);
            }
            return s1.length() - s2.length();
        });
        set.add("cfasd");
        set.add("ab");
        set.add("af");
        set.add("ffa");
        System.out.println(set);
    }
}
